From: Ashe Connor Date: Wed, 18 Oct 2017 06:39:11 +0000 (+1100) Subject: Let's not accept both, just to be safe X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~5^2~36^2 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=0cbfb678e21f8bfbe47887f206a27675ac51df95;p=cargo.git Let's not accept both, just to be safe --- diff --git a/src/bin/install.rs b/src/bin/install.rs index 27b63e197..2d3a135a4 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -1,6 +1,6 @@ use cargo::ops; use cargo::core::{SourceId, GitReference}; -use cargo::util::{CliResult, Config, ToUrl}; +use cargo::util::{CargoError, CliResult, Config, ToUrl}; #[derive(Deserialize)] pub struct Options { @@ -153,7 +153,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { }; let krates = options.arg_crate.iter().map(|s| &s[..]).collect::>(); - let vers = options.flag_version.as_ref().or(options.flag_vers.as_ref()).map(|s| &s[..]); + let vers = match (&options.flag_vers, &options.flag_version) { + (&Some(_), &Some(_)) => return Err(CargoError::from("Invalid arguments.").into()), + (&Some(ref v), _) | (_, &Some(ref v)) => Some(v.as_ref()), + _ => None, + }; let root = options.flag_root.as_ref().map(|s| &s[..]); if options.flag_list { diff --git a/tests/install.rs b/tests/install.rs index c98d4e1ae..da9181f42 100644 --- a/tests/install.rs +++ b/tests/install.rs @@ -933,13 +933,13 @@ fn version_too() { } #[test] -fn version_preferred() { +fn not_both_vers_and_version() { pkg("foo", "0.1.1"); pkg("foo", "0.1.2"); assert_that(cargo_process("install").arg("foo").arg("--version").arg("0.1.1").arg("--vers").arg("0.1.2"), - execs().with_status(0).with_stderr_contains("\ - [DOWNLOADING] foo v0.1.1 (registry [..]) + execs().with_status(101).with_stderr_contains("\ +error: Invalid arguments. ")); }